import os

# home = ".."
home = ""

def relativePath(path):
    if path[0] == "@":
        # return home + path[1:]
        return home + path[2:]
    return path

def loadFromFileRaw(fnm):
    fnm = relativePath(fnm)
    try:
        f = open(fnm)
        ret = f.read()
        f.close()
        return True, ret
    except:
        return False, ""

def writeToFileRaw(fnm, cont):
    fnm = relativePath(fnm)
    path = parseDirname(fnm)
    if not fileExist(path):
        makeDir(path)
    if isinstance(cont, bytes):
        f = open(fnm, "wb")
    else:
        f = open(fnm, "w")
    f.write(cont)
    f.close()

def getCwd():
    return os.getcwd()

def parseDirname(path): # e.g. "/usr/bin/1.cpp"
    return os.path.dirname(path) # "/usr/bin"

def parseFilename(path): # e.g. "/usr/bin/1.cpp"
    return os.path.basename(path) # "1.cpp"

def makeDir(path): # 创建该目录或该文件所在的目录
    path = relativePath(path)
    if os.path.isfile(path):
        path = parseDirname(path)
    os.makedirs(path)

def fileExist(path):
    return os.path.exists(path)